﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

namespace Kevin.Controls
{
    /// <summary>
    /// DialogWindow弹出页面时向新页面发送的QueryString参数类(基类)
    /// </summary>
    public abstract class ParameterItem 
    {
        public ParameterItem()
        { }
        /// <summary>
        /// 抽象基类构造函数
        /// </summary>
        /// <param name="type"></param>
        public ParameterItem(QueryStringType type)
        {
            this.queryStringParameterType = type;
        }

        private QueryStringType queryStringParameterType;

        public QueryStringType QueryStringParameterType
        {
            get { return this.queryStringParameterType; }
        }
        /// <summary>
        /// QueryString项名称
        /// </summary>
        public string QueryStringName
        {
            get;
            set;
        }
        
    }
    /// <summary>
    /// 从控件获取值
    /// </summary>
    public class ControlPara : ParameterItem
    {
        /// <summary>
        /// 构造函数，设定了基类QueryStringType为Control
        /// </summary>
        public ControlPara()
            : base(QueryStringType.Control)
        { }
        /// <summary>
        /// 控件ID
        /// </summary>
        public string ControlID
        {
            get;
            set;
        }
        /// <summary>
        /// 客户端取值的方法，注意：您可以自定义Javascript方法来获取值
        /// 我将给您的这个Javascript方法传入一个参数：ClientControlID
        /// </summary>
        public string ClientMethod
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 从本页的QueryString获取值,如果未指定QueryStringName则使用QueryStringID为参数
    /// </summary>
    public class QueryStringPara : ParameterItem
    {
        /// <summary>
        /// 构造函数，设定了基类QueryStringType为QueryString
        /// </summary>
        public QueryStringPara() : base(QueryStringType.QueryString) { }
        /// <summary>
        /// QueryString request ID
        /// </summary>
        public string QueryStringID
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 从Session中获取值
    /// </summary>
    public class SessionPara : ParameterItem
    {
        /// <summary>
        /// 构造函数，设定了基类QueryStringType为Session
        /// </summary>
        public SessionPara() : base(QueryStringType.Session) { }
        /// <summary>
        /// Session ID
        /// </summary>
        public string SessionID
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 常量参数
    /// </summary>
    public class ConstPara : ParameterItem
    {
        /// <summary>
        /// 构造函数，设定了基类QueryStringType为Const
        /// </summary>
        public ConstPara()
            : base(QueryStringType.Const)
        { }
        /// <summary>
        /// 常量值
        /// </summary>
        public string Value
        {
            get;
            set;
        }

    }
    /// <summary>
    /// DialogWindow控件向新窗口发送QueryString项的集合类
    /// </summary>
    public class ParameterItemCollection : CollectionBase
    {
        /// <summary>
        /// 新增一项
        /// </summary>
        /// <param name="item"></param>
        public void Add(ParameterItem item)
        {
            if (item != null)
                base.List.Add(item);
        }
        /// <summary>
        /// 根据index返回一个参数实例
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public ParameterItem this[int index]
        {
            get { return (ParameterItem)List[index]; }
            set { List[index] = value; }
        }

        /// <summary>
        /// 根据数据的PropertyName判断参数是否已经存在
        /// </summary>
        /// <param name="QueryStringName"></param>
        /// <returns></returns>
        public bool Contains(string QueryStringName)
        {
            foreach (ParameterItem item in this)
            {
                if (item.QueryStringName == QueryStringName)
                    return true;
            }
            return false;
        }
    }

    /// <summary>
    /// QueryString类型
    /// </summary>
    public enum QueryStringType
    {
        /// <summary>
        /// 从本页控件上获取值
        /// </summary>
        Control,
        /// <summary>
        /// 从本页的QueryString中获取值
        /// </summary>
        QueryString,
        /// <summary>
        /// 从Session从中获取值
        /// </summary>
        Session,
        /// <summary>
        /// 常量
        /// </summary>
        Const
    }
}
